#pragma once

#include "base/Logger.h"
#include <random>
#include <numeric>
#include <iostream>
#include <chrono>
#include "protocol/transport.pb.h"

namespace Utils
{
    enum MessageSize
    {
        MAX_MSG_SIZE = 1024 * 1024,
        MAX_SMALL_MSG_SIZE = 256,
        ZMQ_SYNC_WAIT = 1000, // ms
        QUEUE_POLL_WAIT = 20
    };

    static std::unordered_map<transport::ResponseCode, std::string> codeToStringMap = {
        {transport::ResponseCode::RECV_TIMEOUT, "RECV_TIMEOUT"},
        {transport::ResponseCode::UNKNOWN_TYPE, "UNKNOWN_TYPE"},
        {transport::ResponseCode::NO_REPLY, "NO_REPLY"},
        {transport::ResponseCode::HIGH_REQUEST_RATE, "HIGH_REQUEST_RATE"}};

    std::string RandomString(size_t length);

    void SleepMS(int msecs);

    uint64_t GetCurrentTimeMillis();

    std::string CombindString(const std::vector<std::string> &stringList);

    static std::string ResponseCodeToString(transport::ResponseCode code)
    {
        return std::to_string(static_cast<uint32_t>(code));
    }

    static transport::ResponseCode ResponseCodeFromString(std::string code)
    {
        if (code.empty())
        {
            return transport::ResponseCode::UNKNOWN_CODE;
        }
        return static_cast<transport::ResponseCode>(std::stoi(code));
    }

}
